<title>后台管理员</title>
<style>

</style>

<div class="layui-card layadmin-header">
	<div class="layui-breadcrumb" lay-filter="breadcrumb">
		<a lay-href="">主页</a>
		<a><cite>店铺列表</cite></a>
	</div>
</div>

<div class="layui-fluid">
	<div class="layui-card">

		<div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
			<div class="layui-form-item">
				<div class="layui-inline">
						<script type="text/html" template>
							<select name="mall_id">
								<option value="">请选择平台</option>
								{{#  layui.each(jetee['mall'], function(index, item){ }}
								<option value="{{ item['id'] }}">{{ item['name'] }}</option>
								{{#  }); }}
							</select>
						</script>
				</div>
				<div class="layui-inline">
						<script type="text/html" template>
							<select name="status">
								<option value="">审核状态</option>
								{{#  layui.each(lang1['status'], function(index, item){ }}
								<option value="{{ index }}">{{ item }}</option>
								{{#  }); }}
							</select>
						</script>
				</div>
				<div class="layui-inline">
					<input type="text" name="name" placeholder="店铺名称" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
				</div>
			</div>
		</div>

		<div class="layui-card-body">
			<table class="layui-hide"  id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>
			<script type="text/html" id="toolbar">
				<div class="layui-btn-container">
					<button class="layui-btn layuiadmin-btn-admin" data-type="add">审核</button>
				</div>
			</script>
			<script type="text/html" id="imgTpl">
				<img src="{{d.img}}" style="width:50px;height: 50px;"/><br/>
				<a href="{{d.url}}" target="_blank">查看店铺</a>
			</script>
			<script type="text/html" id="buttonTpl">
				{{#  if(d.status == 1){ }}
				<button class="layui-btn layui-btn-xs">{{ lang1['status'][1] }}</button>
				{{#  } else if(d.status == 2) { }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">{{ lang1['status'][2] }}</button>
				{{#  } else { }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">{{ lang1['status'][0] }}</button>
				{{#  } }}
			</script>
			<script type="text/html" id="table-useradmin-admin">
				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			</script>
		</div>
	</div>
</div>



<script>
	layui.contr1='store';
	layui.use(['admin', 'table'], function(){
		var $ = layui.$
			,admin = layui.admin
			,view = layui.view
			,table = layui.table
			,form = layui.form
			,util = layui.util;

		//搜索
		setTimeout(function(){
			form.render(null, 'layadmin-useradmin-formlist');
		}, 100);
		form.on('submit(LAY-user-back-search)', function(data){
			var field = data.field;
			field[layui.setter.request.tokenName]=layui.data(layui.setter.tableName)[layui.setter.request.tokenName];
			//执行重载
			table.reload('LAY-user-back-manage', {
				where: field
			});
		});

		//列表
		table.render({
			elem: '#LAY-user-back-manage'
			,url: './'+layui.contr1+'/list' //id,email,mall_id as mall_name,gapday,name,url,img,status,createtime
			,toolbar: '#toolbar'
			,defaultToolbar: ['filter', 'exports', 'print']
			//,editTrigger: 'dblclick' // 触发编辑的事件类型（默认 click ）。 v2.7.0 新增，之前版本固定为单击触发
			,cols: [[
				{type: 'checkbox', fixed: 'left'},
				{field: 'id', width: 80, title: 'ID', sort: true}
				,{field: 'name', title: '店铺名称', sort: true}
				,{field: 'mall_name', title: '平台', sort: true}
				,{field: 'email', title: '所属商家', sort: true}
				,{field: 'img', title: '后台截图', templet: '#imgTpl'}
				,{field: 'url', title: '店铺链接'}
				,{field: 'gapday', title: '控制接单间隔(天)'}
				,{field: 'createtime', title: '添加时间', sort: true}
				,{field: 'status', title: '审核状态', templet: '#buttonTpl', minWidth: 80, align: 'center', sort: true}
				,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
			]]
			,text: '对不起，加载出现异常！'
			,page: true
			,limit: 30
			,height: 'full-320'
			,lineStyle: 'height: 95px;'
			,done: function(){

			}
			,error: function(res, msg){
				console.log(res, msg)
			}
		});

		//工具条
		table.on('tool(LAY-user-back-manage)', function(obj){
			var data = obj.data;
			if(obj.event === 'edit'){
				admin.popup({
					title: '编辑店铺'
					,area: ['420px', '450px']
					,id: 'LAY-popup-user-add'
					,success: function(layero, index){
						view(this.id).render(layui.contr1+'/info', data).done(function(){
							form.render(null, 'layuiadmin-form-admin');

							//提交
							form.on('submit(LAY-user-back-submit)', function(data){

								//提交 Ajax 成功后，关闭当前弹层并重载表格
								admin.req({
									url: './'+layui.contr1+'/edit'
									,type: 'post'
									,data: data.field
									,done: function(res){
										layui.table.reload('LAY-user-back-manage'); //重载表格
										layer.close(index); //执行关闭
									}
								});

							});

						});
					}
				});
			}
		});

		//点击字段排序
		table.on('sort(LAY-user-back-manage)', function(obj){
			let where=form.val("layadmin-useradmin-formlist");//搜索
			where['sort_by']=obj.field;
			where['sort_order']=obj.type;
			where[layui.setter.request.tokenName]= layui.data(layui.setter.tableName)[layui.setter.request.tokenName];

		table.reload('LAY-user-back-manage', {
				initSort: obj
				,where: where
			});
		});


	});
</script>


